#include <iostream>
#include <stdlib.h>

int main(int argc, char** argv) {

  int n = atoi(argv[1]);

  double *A,*B,*C;

  A = new double[n*n];
  B = new double[n*n];
  C = new double[n*n];

  for (int i=0; i<n; ++i)
    for (int j=0; j<n; ++j) {
      A[i*n+j] = rand();
      B[i*n+j] = rand();
      C[i*n+j] = 0.0;
    }

  for (int i=0; i<n; ++i)
    for (int j=0; j<n; ++j)
      for (int k=0; k<n; ++k)
        C[i*n+j] += A[i*n+k]*B[k*n+j];

  double res = 0.0;
  for (int i=0; i<n; ++i)
    for (int j=0; j<n; ++j) {
      res += C[i*n+j];
    }

  std::cout << "res " << res << std::endl;

  delete[] A;
  delete[] B;
  delete[] C;

  return 0;

}
